<template>
  <div class="home">
    <el-table
            :data="user.slice((currentPage-1)*PageSize,currentPage*PageSize)"
            style="width: 100%">
      <el-table-column
              prop="id"
              label="id"
              width="180">
      </el-table-column>
      <el-table-column
              prop="username"
              label="姓名"
              width="180">
      </el-table-column>
      <el-table-column
              prop="address"
              label="地址">
      </el-table-column>
      <el-table-column
              prop="text"
              label="介绍">
      </el-table-column>
      <el-table-column
              prop="company"
              label="公司名称">
      </el-table-column>
      <el-table-column
              prop="phone"
              label="电话">
      </el-table-column>
    </el-table>
    <el-pagination
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            background
            :page-size="PageSize"
            layout="prev, pager, next"
            :total=count>
    </el-pagination>
  </div>
</template>

<script>
// @ is an alias to /src
import {get,post} from "../network/request";

export default {
  name: 'Home',
  components: {
    HelloWorld
  },
  created(){
    this.getData()
  },
  data(){
    return{
      // 总数据
      user:[],
      // 默认显示第几页
      currentPage:1,
      // 默认每页显示的条数
      PageSize:3,
      // 数据总条数
      count:1,
    }
  },
  methods:{
    getData(){
      post('/index/index/getData',{'page':this.page}).then(res =>{
        this.user = res.data
        this.count = res.data.length
        console.log(res.data.length)
      })
    },
    handleCurrentChange(val) {
      // 改变默认的页数
      // console.log(val)
      this.currentPage = val
    },
  }
}
</script>
